package com.qf.service;

import com.qf.mapper.EmpMapper;
import com.qf.pojo.Emp;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author lixu
 */
@AllArgsConstructor
public class EmpServiceImpl implements BeanNameAware, ApplicationContextAware {

    public EmpServiceImpl() {
        System.out.println("2：EmpServiceImpl执行了构造器");
    }

    //自动注入
    private EmpMapper empMapper;
    public void setEmpMapper(EmpMapper empMapper) {
        System.out.println("3：EmpServiceImpl执行了Set注入");
        this.empMapper = empMapper;
    }

    //初始化方法
    public void init(){
        //加载一些东西。。。、
        System.out.println("5：EmpServiceImpl执行了初始化方法");
    }



    @Override
    public void setBeanName(String s) {
        System.out.println("4：EmpServiceImpl执行了setBeanName");

    }
    //注解 ：  需要扫描
/*    @PostConstruct
    public void customInit(){
        System.out.println("6：EmpServiceImpl执行了自定义初始化方法");
    }*/

    //下面的方法如果不被调用 不能执行
    public List<Emp> findAll(String name) {
        System.out.println("7：EmpServiceImpl执行了findAll");
        return empMapper.findAll(name);
    }
    //销毁
    public void destroy(){
        System.out.println("8：EmpServiceImpl执行了销毁");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("6：EmpServiceImpl执行了setApplicationContext");
    }
}
